package com.lmm.videopager_java;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.lmm.videopager_java.databinding.FragmentVideoBinding;

import java.util.ArrayList;
import java.util.List;

public class VideoFragment extends Fragment {

    public static final String[] urlList = new String[]{
            "https://outin-7478cf551c4811ecaef900163e12ac16.oss-cn-shenzhen.aliyuncs.com/customerTrans/1196025d2d265b43e896c1dbb804e079/3051f37d-17c2b262c1e-0003-ebd2-f44-2066e.mp4?Expires=1641610847&OSSAccessKeyId=LTAI4FocoL6tuCdYhuvug6Ee&Signature=rOeNqSDaAHoldL4IrbQpiGzILNk%3D",
            "https://outin-7478cf551c4811ecaef900163e12ac16.oss-cn-shenzhen.aliyuncs.com/customerTrans/1196025d2d265b43e896c1dbb804e079/49489e04-17c2b052ae5-0003-ebd2-f44-2066e.mp4?Expires=1641610805&OSSAccessKeyId=LTAI4FocoL6tuCdYhuvug6Ee&Signature=8GW3vZhvvkUE0do588mjoMaPmdE%3D",
            "https://outin-7478cf551c4811ecaef900163e12ac16.oss-cn-shenzhen.aliyuncs.com/customerTrans/1196025d2d265b43e896c1dbb804e079/100d1c8-17c2b281c16-0003-ebd2-f44-2066e.mp4?Expires=1641610871&OSSAccessKeyId=LTAI4FocoL6tuCdYhuvug6Ee&Signature=ZMrFRL04nyHf5Fk4bGa3jgjVAvA%3D",
            "https://outin-7478cf551c4811ecaef900163e12ac16.oss-cn-shenzhen.aliyuncs.com/customerTrans/1196025d2d265b43e896c1dbb804e079/17ac026c-17e37651a63-0003-ebd2-f44-2066e.mp4?Expires=1641610897&OSSAccessKeyId=LTAI4FocoL6tuCdYhuvug6Ee&Signature=9OIWNv0Zhhfzkzmh9l6opEuggS4%3D",
            "https://outin-7478cf551c4811ecaef900163e12ac16.oss-cn-shenzhen.aliyuncs.com/customerTrans/1196025d2d265b43e896c1dbb804e079/1382e2e-17e37651a5d-0003-ebd2-f44-2066e.mp4?Expires=1641610911&OSSAccessKeyId=LTAI4FocoL6tuCdYhuvug6Ee&Signature=XNoSZ9Sluu6GUdxyItlrCAetvf4%3D"
    };
    private FragmentVideoBinding binding;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        binding = FragmentVideoBinding.inflate(inflater, container, false);
        return binding.getRoot();
    }


    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        binding.videoViewPager.setAdapter(new FragmentStateAdapter(this) {
            @NonNull
            @Override
            public Fragment createFragment(int position) {
                return new PlayerFragment(urlList[position]);
            }

            @Override
            public int getItemCount() {
                return urlList.length;
            }
        });

        binding.videoViewPager.setOffscreenPageLimit(3);

    }
}